package org.slicerj.core;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SlicingCiterion implements ISlicingCriterion {

	private String packageName;
	private String className;
	private String methodName;
	private int slicingPoint;
	private List<String> variableList = new ArrayList<String>();

	public SlicingCiterion() {

	}

	public SlicingCiterion(String packageName, String className,
			String methodName) {
		setPackageName(packageName);
		setClassName(className);
		setMethodName(methodName);
	}

	public SlicingCiterion(String packageName, String className,
			String methodName, int slicingPoint) {
		new SlicingCiterion(packageName, className, methodName);
		setSlicingPoint(slicingPoint);
	}

	public SlicingCiterion(String packageName, String className,
			String methodName, String variable, int slicingPoint) {
		new SlicingCiterion(packageName, className, methodName, slicingPoint);
		addVariable(variable);
	}

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public void setSlicingPoint(int slicingPoint) {
		this.slicingPoint = slicingPoint;
		printSlicingCriterion();
	}

	@Override
	public int getSlicigPoint() {
		return slicingPoint;
	}

	public List<String> getVariableList() {
		return variableList;
	}

	public String getVariables() {
		StringBuilder vars = new StringBuilder("{");
		for (Iterator<String> iterator = variableList.iterator(); iterator
				.hasNext();) {
			String var = iterator.next();
			vars.append(var + ", ");
		}
		String str = vars.substring(0, vars.length() - 2) + "}";
		return str;
	}

	public void addVariable(String variable) {
		variableList.add(variable);
	}

	public void removeVariable(String variable) {
		variableList.remove(variable);
	}

	private void printSlicingCriterion() {
		System.out.println("<<<<<<<<<<<");
		System.out.println(toString());
		System.out.println(">>>>>>>>>>>");
	}

	public String toString() {
		return getPackageName() + "." + getClassName() + "." + getMethodName()
				+ ":" + getSlicigPoint() + ":" + getVariables();
	}

}
